using PrimeTween;
using UI;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Level
{
    public class SceneLoader : MonoBehaviour
    {
        [SerializeField] private SceneTransition sceneTransition;


        public void LoadScene(int sceneIndex)
        {
            Tween.StopAll();
            sceneTransition.FadeOut(() => SceneManager.LoadScene(sceneIndex));
        }

        public AsyncOperation StartLoadingSceneAsync(int sceneIndex)
        {
            AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneIndex);
            asyncOperation.allowSceneActivation = false;
            return asyncOperation;
        }

        public void ActivateSceneAsync(AsyncOperation asyncOperation)
        {
            sceneTransition.FadeOut(() => asyncOperation.allowSceneActivation = true);
        }
    }
}
